import Koa from 'koa';
import Router from 'koa-router';
import serve from 'koa-static';
import rest from '../middles/rest';
import renderHtml from '../middles/renderHtml';

import API  from '../config/API';
import controllers from '../controllers'
import bodyParser from 'koa-body';
import { STATIC_PATH } from '../constants/PATH';
import auth from '../middles/auth';


const home   = serve(STATIC_PATH);
const router = new Router();
const app  = new Koa();
// app.use(cors());
controllers(router);
app.use(auth);
app.use(home);
app.use(renderHtml());
app.use(rest.restify(API.BASIC_PATH));
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());

export default app;